"use strict";
/**
 * 导出excel，导出的每一个方法自己写
 */
const Controller = require("egg").Controller;

class SimpleController extends Controller {
  async excelUser() {
    const { ctx, app } = this;
    const id = ctx.authUser.id;
    let user = await app.model.User.findOne({
      where: {
        id,
      },
    });
    if (!user) {
      ctx.throw(400, "请先登陆");
    }
    let url = `http://127.0.0.1:7001/getAllUsers`
    // 请求数据参数
    let param = {
      dataType: "json",
      token: "",
    };

    // t:title k:key w:width  ==>表头
    let headers = [
      [
        { t: "ID", k: "id" },
        { t: "用户名", k: "username", w: 20 },
        { t: "昵称", k: "nickname" },
        { t: "邮箱", k: "email" },
        { t: "头像", k: "avatar" },
        { t: "手机", k: "phone" },
        { t: "性别", k: "sex" },
        { t: "个性签名", k: "desc" },
      ],
    ];

    await ctx.helper.excelNew(
      url,
      param,
      headers,
      "绩效考核统计表",
      function (res) {
        return res;
      }
    );
  }
}

module.exports = SimpleController;
